package crp.core.workflow.domain.models;

import com.qwlabs.auditing.AuditedEntity;
import com.vladmihalcea.hibernate.type.array.StringArrayType;
import crp.core.shared.Tables;
import crp.core.shared.hibernate.HibernateTypes;
import io.quarkiverse.hibernate.types.json.JsonTypes;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Getter
@Setter
@Entity
@TypeDef(name = HibernateTypes.STRING_ARRAY, typeClass = StringArrayType.class)
@Table(name = Tables.WORKFLOW_TASK)
public class WorkflowTaskEntity extends AuditedEntity {
    @Id
    @GeneratedValue(generator = "UUID")
    @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
    private String id;
    @ManyToOne(optional = false)
    private WorkflowInstanceEntity instance;
    @Type(type = JsonTypes.JSON_BIN)
    @Column(columnDefinition = JsonTypes.JSON_BIN)
    private WorkflowTaskContext context;
    @Enumerated(EnumType.STRING)
    private ApprovalOperation operation;
    @Enumerated(EnumType.STRING)
    private WorkflowTaskStatus status;
    @Type(type = HibernateTypes.STRING_ARRAY)
    private String[] candidates;

    public String getInstanceId() {
        return instance.getId();
    }
}
